package br.ufpe.cin.dsoa.broker.impl;

import org.osgi.framework.BundleContext;
import org.osgi.framework.Filter;
import org.osgi.framework.ServiceReference;
import org.osgi.util.tracker.ServiceTracker;

import br.ufpe.cin.dsoa.qos.QosDependencyListener;
import br.ufpe.cin.dsoa.qos.ServiceDescription;

public class BrokerTracker extends ServiceTracker {

	private ServiceDescription service;
	private QosDependencyListener qdl;
	private BrokerImpl broker;
	
	public BrokerTracker(BrokerImpl broker, QosDependencyListener qdl, BundleContext context, Filter filter) {
		super(context, filter, null);
		this.broker = broker;
		this.qdl = qdl;
	}	
	
	@Override
	public Object addingService(ServiceReference reference) {
		// TODO Auto-generated method stub
		
		service = broker.bestService(reference);
		System.out.println("Service::" + service.getService().toString());
		qdl.setSelected(service);
		this.close();
		return reference;
	}
	
}
